def list_set_slice():
    """
    在列表中指定位置插入多个数据
    :return:
    """
    test_list = [1, 2, 3, 4, 5, 6]
    # 第一个表示开始插入的下标
    # 第二个表示要插入的数据元素个数
    test_list[3:3] = ['x', 'y', 'z']
    # 打印结果：[1, 2, 3, 'x', 'y', 'z', 4, 5, 6] 因为插入的是列表，所以按顺序插入
    print(test_list)

    new_list = [1, 2, 3, 4, 5, 6]
    new_list[3:3] = {'x', 'y', 'z'}
    # 打印结果 [1, 2, 3, 'z', 'y', 'x', 4, 5, 6] 因为插入的是集合，所以不是按序插入
    print(new_list)


def list_compare():
    """
    进一步证明列表是不可变类型，即使所含数据一样，指向的内存地址不同
    :return:
    """
    a = [1, 2, 3]
    b = [1, 2, 3]
    print(a == b)
    print(a is b)  # is运算符用于判断两个对象的地址是否一致，一致是True
    # 打印结果： False


def use_method():
    a = (1, 2, 3)
    b = ('a', 'b', 'c')

    print(list(zip(a, b)))
    # a和b是列表时的打印结果：[(1, 'a'), (2, 'b'), (3, 'c')]
    # a和b是元组时的打印结果：[(1, 'a'), (2, 'b'), (3, 'c')]
    print(list(zip(b, a)))
    # [('a', 1), ('b', 2), ('c', 3)]
    print(tuple(zip(a, b)))
    # ((1, 'a'), (2, 'b'), (3, 'c'))
    print(dict(zip(a, b)))
    # {1: 'a', 2: 'b', 3: 'c'}

    # enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列
    # 类似于C的enum枚举类型
    seasons = ['Spring', 'Summer', 'Fall', 'Winter']
    text_list = list(enumerate(seasons))
    # [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
    print(text_list)
    text_tuple = tuple(enumerate(seasons))
    # ((0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter'))
    print(text_tuple)
    text_dict = dict(enumerate(seasons))
    # {0: 'Spring', 1: 'Summer', 2: 'Fall', 3: 'Winter'}
    print(text_dict)
    text_set = set(enumerate(seasons))
    # {(0, 'Spring'), (1, 'Summer'), (3, 'Winter'), (2, 'Fall')}
    print(text_set)

    my_dict = dict(text_list)
    print(my_dict)
    # 用于遍历进行值键对换打印，但字典的键值未对换
    print({v: k for k, v in my_dict.items()})
    # {'Spring': 0, 'Summer': 1, 'Fall': 2, 'Winter': 3}
    print(my_dict)
    # {0: 'Spring', 1: 'Summer', 2: 'Fall', 3: 'Winter'}

    # Python特性：i,j=j,i 可进行i与j的交换
    i = 1
    j = 2
    i, j = j, i
    print(i, j)


if __name__ == '__main__':
    # list_set_slice()
    # list_compare()
    use_method()
